import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


def plot():
    # 显示中文
    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False

    # 读入原始数据
    actual = np.array(pd.read_excel('神经网络输入.xlsx', usecols=[7]))
    actual = actual[297:]
    predict = np.array(pd.read_excel('AHC-RBF预测结果.xlsx', header=None))
    x_data = range(38)

    # 将真实值和预测值保存到.txt文件中
    data = np.concatenate((actual, predict), axis=1)
    np.savetxt("./output/ActualAndPredict.txt", data, fmt='%f', delimiter='\t')

    # 画图
    ln1, = plt.plot(x_data, actual, color='red', linestyle='-')
    ln2, = plt.plot(x_data, predict, color='blue', linestyle='-.')
    # 设置标题和坐标轴标签
    plt.title("肉制品检测样本的风险值预测结果")
    plt.xlabel('样本数')
    plt.ylabel('风险值')
    plt.legend(handles=[ln1, ln2], labels=['真实值', '预测值'])
    plt.savefig('./预测结果图.jpg')
    # plt.show()










